package com.ruoyi.product.service.impl;

import java.util.List;

import com.ruoyi.product.mapper.ProductSpecMapper;
import com.ruoyi.product.service.IProductSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.product.mapper.ProductSpecTemplateRelationMapper;
import com.ruoyi.product.domain.ProductSpecTemplateRelation;
import com.ruoyi.product.service.IProductSpecTemplateRelationService;

/**
 * 模板与规格属性的关联Service业务层处理
 *
 * @author liuhuizhong
 * @date 2025-08-07
 */
@Service
public class ProductSpecTemplateRelationServiceImpl implements IProductSpecTemplateRelationService {
    @Autowired
    private ProductSpecTemplateRelationMapper productSpecTemplateRelationMapper;
    @Autowired
    private ProductSpecMapper productSpecMapper;

    /**
     * 查询模板与规格属性的关联
     *
     * @param id 模板与规格属性的关联主键
     * @return 模板与规格属性的关联
     */
    @Override
    public ProductSpecTemplateRelation selectProductSpecTemplateRelationById(Long id) {
        return productSpecTemplateRelationMapper.selectProductSpecTemplateRelationById(id);
    }

    /**
     * 查询模板与规格属性的关联列表
     *
     * @param productSpecTemplateRelation 模板与规格属性的关联
     * @return 模板与规格属性的关联
     */
    @Override
    public List<ProductSpecTemplateRelation> selectProductSpecTemplateRelationList(ProductSpecTemplateRelation productSpecTemplateRelation) {
        List<ProductSpecTemplateRelation> list = productSpecTemplateRelationMapper.selectProductSpecTemplateRelationList(productSpecTemplateRelation);
        if (list.size() > 0) {
            for (ProductSpecTemplateRelation relation : list) {
                relation.setProductSpec(productSpecMapper.selectProductSpecById(relation.getProductSpecId()));
            }
        }
        return list;
    }

    /**
     * 新增模板与规格属性的关联
     *
     * @param productSpecTemplateRelation 模板与规格属性的关联
     * @return 结果
     */
    @Override
    public int insertProductSpecTemplateRelation(ProductSpecTemplateRelation productSpecTemplateRelation) {
        return productSpecTemplateRelationMapper.insertProductSpecTemplateRelation(productSpecTemplateRelation);
    }
    /**
     * 批量新增模板与规格属性的关联
     *
     * @param productSpecTemplateRelationList 模板与规格属性的关联
     * @return 批量结果
     */
    public int insertProductSpecTemplateRelationBatch(List<ProductSpecTemplateRelation> productSpecTemplateRelationList){
        return productSpecTemplateRelationMapper.insertProductSpecTemplateRelationBatch(productSpecTemplateRelationList);
    }

    /**
     * 修改模板与规格属性的关联
     *
     * @param productSpecTemplateRelation 模板与规格属性的关联
     * @return 结果
     */
    @Override
    public int updateProductSpecTemplateRelation(ProductSpecTemplateRelation productSpecTemplateRelation) {
        return productSpecTemplateRelationMapper.updateProductSpecTemplateRelation(productSpecTemplateRelation);
    }

    /**
     * 批量删除模板与规格属性的关联
     *
     * @param ids 需要删除的模板与规格属性的关联主键
     * @return 结果
     */
    @Override
    public int deleteProductSpecTemplateRelationByIds(Long[] ids) {
        return productSpecTemplateRelationMapper.deleteProductSpecTemplateRelationByIds(ids);
    }

    /**
     * 删除模板与规格属性的关联信息
     *
     * @param id 模板与规格属性的关联主键
     * @return 结果
     */
    @Override
    public int deleteProductSpecTemplateRelationById(Long id) {
        return productSpecTemplateRelationMapper.deleteProductSpecTemplateRelationById(id);
    }
    /**
     * 按模板id删除关联
     *
     * @param templateId 需要删除的模板与规格属性的关联主键集合
     * @return 结果
     */
    public int deleteProductSpecTemplateRelationByTemplateId(Long templateId){
        return productSpecTemplateRelationMapper.deleteProductSpecTemplateRelationByTemplateId(templateId);
    }
}
